package com.demo2do.fms.admin.entity.search.data;

import java.util.List;
import java.util.Map;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;

/**
 * 
 * @author Chang Liu
 */
public class TyreFeeSearch implements QueryBuilder{
    
    /** 运输业务公司 */
    private List<Long> organizationIds;
    
    /** 动力类型*/
    private Long powerTypeId;
    
    /** 公里数范围始 */
    private Integer rangeFrom;
    
    /** 公里数范围至 */
    private Integer rangeTo;

    private QueryOrder queryOrder;
    
    private QueryFilter queryFilter;

    /**
     * 
     * the default constructor
     */
    public TyreFeeSearch() {
        queryOrder = new QueryOrder().add("organization.name", "ASC");
    }
    
    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public QueryFilter getPreparedFilter(boolean refresh) {
        
        if(queryFilter == null || refresh) {

            queryFilter = new QueryFilter().addEquals("vehicleFeature.id", powerTypeId)
                                           .addGreaterThanEqual("rangeFrom", rangeFrom)
                                           .addLessThanEqual("rangeTo", rangeTo)
                                           .addSentence("organization.id IN (:organizationIds)", "organizationIds", organizationIds);
        }
        
        return queryFilter;
        
    }
    
    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
     */
    public QueryOrder getOrder() {
        return queryOrder;
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        String sentence = "FROM TyreFee WHERE 1 = 1" + getPreparedFilter(false).clauseSentence() + queryOrder.sentence();
        return sentence;
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).parameters();
    }
    
    /**
     * 
     * @return
     */
    public QueryFilter getFilter(){
        return getPreparedFilter(false);
    }
    
    /**
     * 
     * @return organizationIds
     */
    public List<Long> getOrganizationIds() {
        
        return organizationIds;
    }
    
    /**
     * @return the powerTypeId
     */
    public Long getPowerTypeId() {
        return powerTypeId;
    }

    /**
     * @return the rangeFrom
     */
    public Integer getRangeFrom() {
        return rangeFrom;
    }

    /**
     * @return the rangeTo
     */
    public Integer getRangeTo() {
        return rangeTo;
    }
    
    /**
     * @param organizationIds the organizationIds to set
     */
    public void setOrganizationIds(List<Long> organizationIds) {
        this.organizationIds = organizationIds;
    }
    
    /**
     * @param powerTypeId the powerTypeId to set
     */
    public void setPowerTypeId(Long powerTypeId) {
        this.powerTypeId = powerTypeId;
    }

    /**
     * @param rangeFrom the rangeFrom to set
     */
    public void setRangeFrom(Integer rangeFrom) {
        this.rangeFrom = rangeFrom;
    }

    /**
     * @param rangeTo the rangeTo to set
     */
    public void setRangeTo(Integer rangeTo) {
        this.rangeTo = rangeTo;
    }

    /**
     * @param organizationIds the organizationIds to set
     */
/*    public void setOrganizationIds(List<Long> organizationIds) {
        this.organizationIds = organizationIds;
    }*/
    
    
    
}
